# Copyright 2022 99Cloud, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# flake8: noqa
# fmt: off

"""add lidar

Revision ID: ec54a0a8f04a
Revises: a53f58b7c8b3
Create Date: 2022-09-14 16:42:37.107563

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "ec54a0a8f04a"
down_revision = "a53f58b7c8b3"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "lidar",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("create_time", sa.DateTime(), nullable=False),
        sa.Column("update_time", sa.DateTime(), nullable=False),
        sa.Column("sn", sa.String(length=64), nullable=False),
        sa.Column("name", sa.String(length=64), nullable=False),
        sa.Column("lidar_ip", sa.String(length=15), nullable=False),
        sa.Column("lng", sa.Float(), nullable=False),
        sa.Column("lat", sa.Float(), nullable=False),
        sa.Column("elevation", sa.Float(), nullable=False),
        sa.Column("towards", sa.Float(), nullable=False),
        sa.Column("online_status", sa.Boolean(), nullable=False),
        sa.Column("enabled", sa.Boolean(), nullable=False),
        sa.Column("point", sa.String(length=15), nullable=False),
        sa.Column("pole", sa.String(length=15), nullable=False),
        sa.Column("rsu_id", sa.Integer(), nullable=True),
        sa.Column("desc", sa.String(length=255), nullable=False),
        sa.ForeignKeyConstraint(
            ["rsu_id"],
            ["rsu.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_lidar_id"), "lidar", ["id"], unique=False)
    op.create_index(op.f("ix_lidar_name"), "lidar", ["name"], unique=False)
    op.create_index(op.f("ix_lidar_sn"), "lidar", ["sn"], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_lidar_sn"), table_name="lidar")
    op.drop_index(op.f("ix_lidar_name"), table_name="lidar")
    op.drop_index(op.f("ix_lidar_id"), table_name="lidar")
    op.drop_table("lidar")
    # ### end Alembic commands ###
